package app

import (
	"fmt"
	"github.com/gin-gonic/gin"
	xerrors "github.com/pkg/errors"
	"trainingGo/base"
)

func getUser(ctx *gin.Context) {
	uID := ctx.Query("limit")
	db := base.GetDB()

	var name string
	err := db.QueryRow("select name, age from users where id = ? ", uID).Scan(&name)
	if err != nil {
		err = xerrors.Wrap(err, fmt.Sprintf("getUser: uID is %s", uID))
		ctx.Set("errors", err)
		return
	}

	ctx.JSON(200, gin.H{"name": name})
}
